#### Restrict results to competitive elections ####
primary_margin <- primary %>% 
  filter(ppct >= 30 &
           ppct <= 70)

general_margin <- general %>% 
  filter(gpct >= 45 &
           gpct <= 55)

# Primary congressional elections
mod_primary_margin <- lm(form_primary_main,
                         data = primary_margin)

primaryr2 <- get_r2(mod_primary_margin)
mod_primary_margin <- get_clusters(mod_primary_margin)

# General congressional elections
mod_general_margin <- lm(form_general_main,
                         data = general_margin)

generalr2 <- get_r2(mod_general_margin)
mod_general_margin <- get_clusters(mod_general_margin)

stargazer(mod_general_margin, mod_primary_margin,
          type = "latex",
          title = "Relationship Between Name Fluency and Vote Share in Competitive Elections",
          style = style,
          star.cutoffs = star.cutoffs,
          star.char = star.char,
          column.labels = c("General Elections", "Primary Elections"),
          keep.stat = keep.stat,
          notes = notes,
          keep = keep_congress,
          covariate.labels = covariate.labels_congress,
          font.size = "footnotesize",
          model.names = F,
          add.lines=list(c("Year FE", "\\checkmark", "\\checkmark"),
                         c("State FE", "\\checkmark", "\\checkmark"),
                         c("N", get_n(mod_general_margin), get_n(mod_primary_margin)),
                         c("Adj. R-squared", generalr2, primaryr2)),
          out = "tables/reg-competitive.tex",
          label = "tab:reg-competitive")

